package com.chuangjiangx.member.basic.web.controller;

import com.chuangjiangx.commons.BeanUtils;
import com.chuangjiangx.commons.CurrentThreadContext;
import com.chuangjiangx.commons.response.Response;
import com.chuangjiangx.commons.response.ResponseUtils;
import com.chuangjiangx.member.basic.web.interceptor.Login;
import com.chuangjiangx.member.stored.web.response.StoreSearchResponse;
import com.chuangjiangx.member.basic.ddd.query.MerchantInfoQuery;
import com.chuangjiangx.member.basic.ddd.dal.dto.StoreList;
import com.chuangjiangx.member.basic.ddd.domain.model.MbrUserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Auther: YZJ
 * @Date: 2018/8/29 09:52
 * @Description:H5门店
 */
@Slf4j
@RestController
@RequestMapping(value = "/h5/store")
@Api(value = "StoreController", tags = "门店", description = "")
public class StoreController {
    @Autowired
    private MerchantInfoQuery merchantInfoQuery;
    /**
     * 查询门店列表
     *
     * @param session
     * @return Response
     */
    @GetMapping(value = "/search-list")
    @ApiOperation(value = "查询商户列表")
    @Login
    public Response storeSearch(@ApiIgnore HttpSession session) {
        MbrUserContext user = (MbrUserContext) CurrentThreadContext.getCurrentUser();
        List<StoreList> storeLists = merchantInfoQuery.queryStoreListByEnableAndMerchantId(user.getMerchantId());
        List<StoreSearchResponse> storeSearchResponses = BeanUtils.convertCollection(storeLists, StoreSearchResponse.class,(s, res) -> res.setStoreName(s.getName()));
        return ResponseUtils.success(storeSearchResponses);
    }
}
